package cumt.oj;

import java.util.Scanner;

/**
 * @Author Fizz Pu
 * @Date 2020/11/6 下午2:07
 * @Version 1.0
 * 失之毫厘，缪之千里！
 */
public class Problem1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String encyString;
        int offset;
        int count = scanner.nextInt();
        for(int i = 0; i < count; ++i){
            encyString = scanner.next();
            offset = scanner.nextInt();
            offset = offset % 26; // 取模
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < encyString.length(); ++j){
                int ascii = encyString.charAt(j);
                if(ascii <= 'z' && ascii >= 'a'){
                    ascii = ascii - offset;
                    if(ascii < 'a'){
                         ascii = 'z' - ('a' - ascii - 1);
                     }
                } else if(ascii >= 'A' & ascii <= 'Z'){
                    ascii = ascii - offset;
                    if(ascii < 'A'){
                        ascii = 'Z' - ('A' - ascii - 1);
                    }
                }
                sb.append((char) ascii);
            }
            System.out.println(sb.toString());
        }
    }
}
